using UnityEngine;

public class ActionStateType
{
    //player
    public const int idle = 1;
    public const int run = 2;
    public const int attack = 3;
    public const int byHit = 4;
    public const int die = 5;
}

/// <summary>
/// idle
/// </summary>
public class ActionStateIdle : ActionState
{
    public override int stateId => ActionStateType.idle;

    public ActionStateIdle(PlayerActionFSM fsm) : base(fsm)
    {
        
    }

    public override void OnEnter(FSMState preState)
    {
        base.OnEnter(preState);

        role.StopMove();
        if(role.roleAnim)
            role.roleAnim.SetAnimatorBool("Move",false);

        GameDebug.LogShowy($"Idle Enter preState:{preState?.stateId}");
    }
    public override void OnExit(FSMState nextState)
    {
        base.OnExit(nextState);

        GameDebug.LogShowy($"Idle Exit  nextState:{nextState?.stateId}");
    }
}

public class ActionStateByHit : ProgressAction
{
    private const float byHitTime = 0.25f;

    public override int stateId => ActionStateType.byHit;

    public ActionStateByHit(PlayerActionFSM fsm) : base(fsm)
    {
        this.m_TotalTime = byHitTime;
    }

    public override void OnEnter(FSMState preState)
    {
        base.OnEnter(preState);
        
//        GameDebug.LogError($"进入受击：{this.role.gameObject.name}  time:{this.role.battleController.time}  m_TotalTime:{m_TotalTime}");
        
        this.role.StopMove();
        if (role.roleAnim)
            role.roleAnim.SetAnimatorTrigger("Hurt");
    }

    public override void Update(float deltaTime)
    {
        base.Update(deltaTime);
        
        //if (role.rc)
        //    role.rc.zRoleAnim.PlayAnim(ActionType.Hurt, progress);
    }
}

/// <summary>
/// attack
/// </summary>
public class ActionStateAttack : ProgressAction
{
    public override int stateId => ActionStateType.attack;
    
    const float execuateTime = 0.1f;
    const float normalActionTime = 0.2f;

    public ActionStateAttack(PlayerActionFSM fsm) : base(fsm)
    {
        m_TotalTime = normalActionTime;
        m_ExecuteTime = execuateTime;
    }

    public override void OnEnter(FSMState preState)
    {
        base.OnEnter(preState);
        
#if DEBUG
        GameDebug.Log($"attack  begin time:{this.role.battleController.time}  {this.role.name}");
#endif

        //this.role.StopMove();

        if(role.roleAnim)
            this.role.roleAnim.SetAnimatorTrigger("Attack");
    }


    public override void OnExit(FSMState nextState)
    {
        base.OnExit(nextState);
        
#if UNITY_EDITOR
        GameDebug.Log($"attack end time：{this.role.battleController.time}");
#endif
    }
}

/// <summary>
/// die
/// </summary>
public class ActionStateDie : ActionState
{
    public override int stateId => ActionStateType.die;


    public ActionStateDie(PlayerActionFSM fsm) : base(fsm)
    {
        
    }

    public override void OnEnter(FSMState preState)
    {
        base.OnEnter(preState);

        if(this.role.roleAnim)
            role.roleAnim.SetAnimatorTrigger("Lose");

        role.ShowDieGo();
        role.StopMove();

        //DoActionDelay.DelayAction(1.5f, () => player.Rigidbody.isKinematic = true);

        GameDebug.LogError($"{role.name} die begin  :{Time.time}");

        role.gameObject.layer = BattleController.layerIgnoreRaycast;
    }
}
